MsgBox exceltojson("dataset.xlsx","Sheet1")

Function exceltojson(filename,sheetname)

Dim xlApp, xlFile, xlSheet
Dim ccount,rcount, iLoop, numAdd
Dim labelarr(),datacarr(),dataarr()
Set xlApp = CreateObject ("Excel.Application")
Set xlFile = xlApp.Workbooks.Open (filename)  
Set xlSheet = xlFile.Sheets(sheetname)
ccount=xlSheet.usedRange.Columns.Count
rcount=xlSheet.usedRange.Rows.Count 
If ccount>=2 Then
	ReDim labelarr(ccount)
	ReDim dataarr(rcount-1)
	ReDim datacarr(ccount-1)
	For cloop = 1 To ccount-1
		labelarr(cloop)=xlSheet.Cells(1,cloop+1)
		'MsgBox labelarr(cloop)
	Next
	For rloop= 2 To rcount
		For cloop =1 To ccount
			dataarr(cloop)=xlSheet.Cells(rloop,cloop)
			'MsgBox dataarr(cloop)
		Next
		For cloop =1 To ccount-1
			datacarr(cloop)=smalldataset(datacarr(cloop),dataarr(1),dataarr(cloop+1))
			'MsgBox datacarr(cloop)
		Next
	Next
	
	For cloop = 1 To ccount-1 
	result=middataset(result,labelarr(cloop),datacarr(cloop))
	'result=middataset("ALL",data1)+","+middataset("PASS",data2)+","+middataset("FAIL",data3)+","+middataset("Not Run",data4)
	Next
	xlApp.Workbooks.Close
	Set xlSheet = Nothing
	Set xlFile = Nothing
	Set xlApp = Nothing
	
	exceltojson=result
Else
	exceltojson="error"
End if
'MsgBox result



End Function




public function smalldataset(old,item1,item2)
if old="" or isnull(old) then
	smalldataset="["+cstr(item1)+","+cstr(item2)+"]"
else
	smalldataset=old+",["+cstr(item1)+","+cstr(item2)+"]"
end if
end function

public function middataset(old,label,item)
If old="" Or IsNull(old) Then
	middataset=""""+cstr(label)+""": {label:"""+cstr(label)+""",data:["+item+"]}"
Else
	middataset=old+","""+cstr(label)+""": {label:"""+cstr(label)+""",data:["+item+"]}"
End if
end function